<template>
	<uni-nav-bar title="任务中心" :border="false" :fixed="true" background-color="#FFFFFF" statusBar="true"
		@clickRight="addWorkBtn" @clickLeft="back" style="z-index: 2;">
		<template #right>
			<view style="font-size: 16px;">发布</view>
		</template>
		<template #left>
			<view style="font-size: 16px;">取消</view>
		</template>
	</uni-nav-bar>
	<view>
		<up-input placeholder="请输入标题(2~30个字)" maxlength="20" border="" fontSize="20" v-model="title"
			@change="change"></up-input>
	</view>
	<view style="margin: 10px auto;width: 95%;">
		<text style="margin-left: ;">任务金额</text>
		<u-number-box style="margin: 20px auto;" v-model="money" button-size="36" :min="5" integer :max="100"
			@change="valChange"></u-number-box>
	</view>
	<view style="margin: 10px auto;width: 95%;">
		<text style="margin-left: ;">任务时间</text>
		<u-number-box style="margin: 20px auto;" v-model="time" button-size="36" :min="5" integer :max="100"
			@change="valChange"></u-number-box>
	</view>
	<view style="height: 200px; width: 95%;margin:  10px auto;">
		<textarea :disable-default-padding="true" @blur="bindTextAreaBlur" placeholder-style="color:#C0C4CC"
			v-model="content" auto-height placeholder="请输入正文" maxlength="50" />
	</view>
</template>

<script>
	import {
		addWork
	} from "../../request/API/addWork";
	export default {
		data() {
			return {
				content: "",
				title: "",
				money: 5,
				time: 30
			}
		},
		methods: {
			addWorkBtn() {
				const title = this.title
				const content = this.content
				const money = this.money
				const time = this.time
				addWork({
						title,
						content,
						money,
						time
					})
					.then(data => {
						console.log(data)
						uni.showToast({
							title: data.msg,
							icon: 'none',
						});
						uni.reLaunch({
							url: '/pages/index/housework' // 重定向到首页，刷新页面
						});
					})
					.catch(Error => {
						uni.showToast({
							title: Error.msg,
							icon: 'none',
						});
					})
			},
			back() {
				uni.navigateBack({
					delta: 1,
					animationType: 'slide-out-bottom',
					animationDuration: 300
				});
			}
		}
	}
</script>

<style>
</style>